﻿$wordPath = "D:\Docs\贵州\不动产登记系统与房产交易系统接口对接_20151217.docx";

#PowerShell可以通过COM接口控制Word应用程序
$objWord = New-Object -Com Word.Application

$filename =$wordPath
$objDocument = $objWord.Documents.Open($filename)

$objDocument.Tables.Count;
<#
$LETable = $objDocument.Tables.Item(1)
$LETableCols = $LETable.Columns.Count
$LETableRows = $LETable.Rows.Count


Write-output "Starting to write... "

for($r=1; $r -le $LETableRows; $r++) {
    for($c=1; $c -le $LETableCols; $c++) {
        Write-host $r "x" $c
        $content = $LETable.Cell($r,$c).Range.Text
        Write-host $content
    }
}

$objDocument.Close()
$objWord.Quit()
# Stop Winword Process
$rc = [System.Runtime.Interopservices.Marshal]::ReleaseComObject($objWord)
#>

<#
$wd = New-Object -ComObject Word.Application
$wd.Visible = $true
$doc = $wd.Documents.Open($filename)
$doc.Tables | ForEach-Object {
  $_.Cell($_.Rows.Count, $_.Columns.Count).Range.Text
}
#>